Retain existing leveraged ETF shares for small accounts#163
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5b0fb78508
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| target_value = max(0.0, float(compatibility_targets.get(symbol, 0.0) or 0.0)) | ||
| price = max(0.0, float(quote_prices.get(symbol, 0.0) or 0.0)) | ||
| if price > 0.0 and 0.0 < target_value < price and quantities.get(symbol, 0.0) >= 1.0: | ||
| compatibility_targets[symbol] = price |
There was a problem hiding this comment.
Avoid retaining an extra share when quotes tick up
When the order quote is even slightly above the portfolio snapshot's per-share valuation, setting the retained target to exactly price makes _sell_order_quantity compute (current_value - price) / price and then floor it below held - 1; for example, 7 TQQQ shares valued at $541.31 with a fresh quote of $77.34 sells only 5 shares, leaving 2 instead of the intended minimum whole share. Derive the retained target/order quantity from the held quantity, or otherwise account for quote/snapshot drift before flooring.
Useful? React with 👍 / 👎.
Summary
Tests